package com.leejie.springboot01.java8;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author leejie
 * @version 1.0
 * @date 2021/9/17 19:31
 */
public class ForeachLamda {

    public static void main(String[] args) {
        mapLamda();
    }

    public static void mapLamda(){
        Map<String, Integer> items = new HashMap<>();
        items.put("A", 10);
        items.put("B", 20);
        items.put("C", 30);
        items.put("D", 40);
        items.put("E", 50);
        items.put("F", 60);


        System.out.println("java8之前的遍历：-------------");
        for (Map.Entry<String,Integer> entry : items.entrySet()){

            System.out.println("Item : " + entry.getKey() + " Count : " + entry.getValue());
        }

        System.out.println("lamda表达式遍历--------------");
        items.forEach((k,v)-> System.out.println("Item : " + k + " Count : " + v));
        items.forEach((k,v)->{
            System.out.println("Item : " + k + " Count : " + v);
            if ("E".equals(k)){
                System.out.println("hello EEE...");
            }
        });


        System.out.println("lambda表达式遍历List集合-------------");
        List<String> item = new ArrayList<>();
        item.add("A");
        item.add("B");
        item.add("C");
        item.add("D");
        item.add("E");

//        for (String s : item) {
//            System.out.println(s);
//        }

        item.forEach(item1-> System.out.println(item1));

    }
}
